﻿Imports System
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports ExtensionLibrary

''' <summary>
''' Tests the <see cref="StringExtensions">StringExtensions</see> class.
''' </summary>
''' <revisions>
''' <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
''' </revisions>
<TestClass()> _
Public Class StringExtensionsTest

  Private testContextInstance As TestContext

  ''' <summary>
  ''' Gets or sets the test context which provides information about and functionality for the current test run.
  ''' </summary>
  ''' <value>The test context.</value>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  Public Property TestContext() As TestContext
    Get
      Return testContextInstance
    End Get
    Set(ByVal value As TestContext)
      testContextInstance = value
    End Set
  End Property

#Region " ToInt16"

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt16">ToInt16</see> method specifying a string set to Null (Nothing in Visual Basic).
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt16Test1()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int16

    ' Test when the input is Nothing
    strInput = Nothing
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt16)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt16">ToInt16</see> method specifying an empty string
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt16Test2()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int16

    ' Test when the input is empty
    strInput = ""
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt16)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt16">ToInt16</see> method specifying a string set to a non-numeric value.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt16Test3()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int16

    ' Test when the input is not numeric
    strInput = "USAAC"
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt16)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt16">ToInt16</see> method with specifying a numerical value within the limits of an <see cref="Int16">Int16</see>
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt16Test4()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int16

    ' Test when the input is a valid numeric value
    strInput = "3200"
    shtExpected = 3200
    Assert.AreEqual(shtExpected, strInput.ToInt16)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt16">ToInt16</see> method with a value that is too small.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToInt16Test5()
    Assert.AreEqual(0, "-64000".ToInt16)
  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt16">ToInt16</see> method with a value that is too large.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToInt16Test6()
    Assert.AreEqual(0, "64000".ToInt16)
  End Sub

#End Region

#Region " ToInt32"

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt32">ToInt32</see> method specifying a string set to Null (Nothing in Visual Basic).
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt32Test1()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int32

    ' Test when the input is Nothing
    strInput = Nothing
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt32)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt32">ToInt32</see> method specifying an empty string
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt32Test2()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int32

    ' Test when the input is empty
    strInput = ""
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt32)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt32">ToInt32</see> method specifying a string set to a non-numeric value.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt32Test3()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int32

    ' Test when the input is not numeric
    strInput = "USAAC"
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt32)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt32">ToInt32</see> method with specifying a numerical value within the limits of an <see cref="Int32">Int32</see>
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt32Test4()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int32

    ' Test when the input is a valid numeric value
    strInput = "1123123"
    shtExpected = 1123123
    Assert.AreEqual(shtExpected, strInput.ToInt32)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt32">ToInt32</see> method with a value that is too small.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToInt32Test5()
    Assert.AreEqual(0, "-2147483650".ToInt32)
  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt32">ToInt32</see> method with a value that is too large.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToInt32Test6()
    Assert.AreEqual(0, "2147483648".ToInt32)
  End Sub

#End Region

#Region " ToInt64"

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt64">ToInt64</see> method specifying a string set to Null (Nothing in Visual Basic).
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt64Test1()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int64

    ' Test when the input is Nothing
    strInput = Nothing
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt64)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt64">ToInt64</see> method specifying an empty string
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt64Test2()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int64

    ' Test when the input is empty
    strInput = ""
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt64)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt64">ToInt64</see> method specifying a string set to a non-numeric value.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt64Test3()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int64

    ' Test when the input is not numeric
    strInput = "USAAC"
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToInt64)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt64">ToInt64</see> method with specifying a numerical value within the limits of an <see cref="Int64">Int64</see>
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToInt64Test4()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Int64

    ' Test when the input is a valid numeric value
    strInput = "1123123"
    shtExpected = 1123123
    Assert.AreEqual(shtExpected, strInput.ToInt64)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt64">ToInt64</see> method with a value that is too small.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToInt64Test5()
    Assert.AreEqual(0, "-9223372036854775810".ToInt64)
  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToInt64">ToInt64</see> method with a value that is too large.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToInt64Test6()
    Assert.AreEqual(0, "9223372036854775810".ToInt64)
  End Sub

#End Region

#Region " ToDecimal"

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToDecimal">ToDecimal</see> method specifying a string set to Null (Nothing in Visual Basic).
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToDecimalTest1()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Decimal

    ' Test when the input is Nothing
    strInput = Nothing
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToDecimal)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToDecimal">ToDecimal</see> method specifying an empty string
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToDecimalTest2()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Decimal

    ' Test when the input is empty
    strInput = ""
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToDecimal)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToDecimal">ToDecimal</see> method specifying a string set to a non-numeric value.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToDecimalTest3()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Decimal

    ' Test when the input is not numeric
    strInput = "USAAC"
    shtExpected = 0
    Assert.AreEqual(shtExpected, strInput.ToDecimal)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToDecimal">ToDecimal</see> method with specifying a numerical value within the limits of an <see cref="Decimal">Decimal</see>
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToDecimalTest4()

    ' Variable Declarations
    Dim strInput As String
    Dim shtExpected As Decimal

    ' Test when the input is a valid numeric value
    strInput = "3200.015"
    shtExpected = 3200.015
    Assert.AreEqual(shtExpected, strInput.ToDecimal)

  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToDecimal">ToDecimal</see> method with a value that is too small.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToDecimalTest5()
    Assert.AreEqual(0, "-79228162514264337593543950340".ToDecimal)
  End Sub

  ''' <summary>
  ''' Tests the <see cref=" StringExtensions.ToDecimal">ToDecimal</see> method with a value that is too large.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> <ExpectedException(GetType(OverflowException))> Public Sub ToDecimalTest6()
    Assert.AreEqual(0, "79228162514264337593543950340".ToDecimal)
  End Sub

#End Region

#Region " FormatPhoneNumber"

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatPhoneNumber">FormatPhoneNumber</see> method specifying a phone number with an area code and extension.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatPhoneNumberTest1()
    Assert.AreEqual("(502) 626-1331 x1331", "50262613311331".FormatPhoneNumber)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatPhoneNumber">FormatPhoneNumber</see> method specifying a phone number with an area code.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatPhoneNumberTest2()
    Assert.AreEqual("(502) 626-1331", "5026261331".FormatPhoneNumber)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatPhoneNumber">FormatPhoneNumber</see> method specifying a phone number.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatPhoneNumberTest3()
    Assert.AreEqual("626-1331", "6261331".FormatPhoneNumber)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatPhoneNumber">FormatPhoneNumber</see> method specifying a formatted phone number.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatPhoneNumberTest4()
    Assert.AreEqual("(502) 626-1331", "(502) 626-1331".FormatPhoneNumber)
  End Sub

#End Region

#Region " FormatDateTime"

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatDateTime">FormatDateTime</see> method specifying to include the time.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatDateTimeTest1()
    Assert.AreEqual("12-JUN-2008 14:19:30", "06/12/2008 14:19:30".FormatDateTime(True))
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatDateTime">FormatDateTime</see> method specifying to not include the time.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatDateTimeTest2()
    Assert.AreEqual("12-JUN-2008", "06/12/2008 14:19:30".FormatDateTime(False))
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatDateTime">FormatDateTime</see> method specifying an invalid date.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatDateTimeTest3()
    Assert.AreEqual("N/A", "Not A Date Value".FormatDateTime(True))
  End Sub

#End Region

#Region " FormatContentLength"

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatContentLength">FormatContentLength</see> method specyfing a value within the byte range.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatContentLengthTest1()
    Assert.AreEqual("100 bytes", "100".FormatContentLength)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatContentLength">FormatContentLength</see> method specyfing a value within the kilobyte range.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatContentLengthTest2()
    Assert.AreEqual("1.00 KB", "1025".FormatContentLength)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatContentLength">FormatContentLength</see> method specyfing a value within the megabyte range.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatContentLengthTest3()
    Assert.AreEqual("1.00 MB", "1048576".FormatContentLength)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.FormatContentLength">FormatContentLength</see> method specyfing a value within the gigabyte range.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub FormatContentLengthTest4()
    Assert.AreEqual("1.00 GB", "1073741825".FormatContentLength)
  End Sub

#End Region

#Region " GetNumberOfInstancesOfCharacter"

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.GetNumberOfInstancesOfCharacter">GetNumberOfInstancesOfCharacter</see> method where there are no instances of the specified character.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub GetNumberOfInstancesOfCharacterTest1()
    Assert.AreEqual(0, "USAAC".GetNumberOfInstancesOfCharacter("D"))
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.GetNumberOfInstancesOfCharacter">GetNumberOfInstancesOfCharacter</see> method where there are instances of the specified character.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub GetNumberOfInstancesOfCharacterTest2()
    Assert.AreEqual(2, "USAAC".GetNumberOfInstancesOfCharacter("A"))
  End Sub

#End Region

#Region " ToBoolean"

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.ToBoolean">ToBoolean</see> method specifying a value that should evaluate to <c>True</c>.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToBooleanTest1()
    Assert.IsTrue("TRUE".ToBoolean)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.ToBoolean">ToBoolean</see> method specifying a value that should evaluate to <c>False</c>.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToBooleanTest2()
    Assert.IsFalse("FALSE".ToBoolean)
  End Sub

  ''' <summary>
  ''' Tests the <see cref="StringExtensions.ToBoolean">ToBoolean</see> method specifying a non-boolean value.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ToBooleanTest()
    Assert.IsFalse("USAAC".ToBoolean)
  End Sub

#End Region

#Region " Reverse"

  ''' <summary>
  ''' Tests the <see cref="Reverse">Reverse</see> method.
  ''' </summary>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <TestMethod()> Public Sub ReverseTest()
    Dim strExpected As String = "POIUYTREWQ"
    Dim strActual As String = "QWERTYUIOP"
    strActual.Reverse()
    Assert.AreEqual(strExpected, strActual)
  End Sub

#End Region

End Class